package cn.zyjblogs.starter.common.utils.lang;

import cn.zyjblogs.starter.common.exception.AssartRuntimeException;
import cn.zyjblogs.starter.common.exception.CommonBusinessException;
import cn.zyjblogs.starter.common.utils.collections.CollectionUtils;
import cn.zyjblogs.starter.common.utils.string.StringUtils;
import org.apache.commons.lang3.ArrayUtils;

import java.util.Collection;
import java.util.Map;

public final class Asserts {
    public Asserts() {
    }

    public static void isTrue(boolean expression, String message, Object... params) {
        if (!expression) {
            throw new AssartRuntimeException(StringUtils.format(message,params));
        }
    }

    public static void isFalse(boolean expression, String message, Object... params) {
        isTrue(!expression, message, params);
    }

    public static void isNull(Object object, String message, Object... params) {
        isTrue(object == null, message, params);
    }

    public static void notNull(Object object, String message, Object... params) {
        isTrue(object != null, message, params);
    }

    public static void notEmpty(String value, String message, Object... params) {
        isTrue(StringUtils.isNotBlank(value), message, params);
    }

    public static void notEmpty(Collection<?> collection, String message, Object... params) {
        isTrue(CollectionUtils.isNotEmpty(collection), message, params);
    }

    public static void notEmpty(Map<?, ?> map, String message, Object... params) {
        isTrue(CollectionUtils.isNotEmpty(map), message, params);
    }

    public static void isEmpty(Map<?, ?> map, String message, Object... params) {
        isTrue(CollectionUtils.isEmpty(map), message, params);
    }

    public static void notEmpty(Object[] array, String message, Object... params) {
        isTrue(ArrayUtils.isNotEmpty(array), message, params);
    }
}
